from pynput import keyboard
from playsound import playsound
import os
from threading import Thread


# 假设ffmpeg安装在以下路径
ffmpeg_path = 'D:\python\gitee\pythonProject\.venv\Lib\site-packages/ffmpeg'

# 将ffmpeg路径添加到PATH环境变量中
os.environ["PATH"] += os.pathsep  + ffmpeg_path

# 现在pydub应该能够找到并使用ffmpeg了
from pydub import AudioSegment

path = 'D:\music'
musics = []
for mkdir,_,filename in os.walk(path) :
    for a in filename :
        musics.append(f'{mkdir}/{a}')

print(musics)
# sound = AudioSegment.from_mp3(musics[0])
#
# timeout = 1000
# for i in range(0,30):
#     tmp = sound[(i*timeout):((i + 1)*timeout)]
#     tmp.export(f'{i + 1}.mp3',format='mp3')

# def fun(key) :
#     th = Thread(target=playsound,args=(musics[0],))
#     th.daemon = True
#     th.start()
#
#
# listener = keyboard.Listener(fun)
# listener.start()
# listener.join()